﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using Common.Utilities;
using Common.Utilities.Dispatcher;

namespace Workflows.Components.Reports
{
    /// <summary></summary>
    [Serializable]
    public class ExcelReportOutput:ResultBase
    {
        private string _ExcelReportFilePath;
        /// <summary></summary>
        public string ExcelReportFilePath
        {
            get
            {
                return this._ExcelReportFilePath;
            }
            set
            {
                this._ExcelReportFilePath = value;
            }
        }
        /// <summary></summary>
        public ExcelReportOutput():base(Guid.Empty,Guid.Empty)
        {
            this._ExcelReportFilePath = string.Empty;
        }
        /// <summary></summary>
        public ExcelReportOutput(Guid componentID, Guid jobTicketID, string reportFilePath) 
            : base(componentID, jobTicketID)
        {
            this._ExcelReportFilePath = reportFilePath;
        }
        /// <summary></summary>
        public override XmlNode Serialize(ref XmlDocument xDoc, ref XmlNode parentNode)
        {
            XmlNode xNode = XmlDataUtil.AddElement(ref xDoc, parentNode, "Output");
            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "Type", this.GetType().FullName);
            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "WorkerID", this.OwnerWorkerInstanceID.ToString());
            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "FinishTime", this.FinishTime.ToString());

            XmlDataUtil.UpdateAttribute(ref xDoc, xNode,"ReportFilePath",this.ExcelReportFilePath);

            return xNode;
        }
        /// <summary></summary>
        public override ResultBase Instantiate(XmlNode xNode)
        {
            if (xNode.Attributes.GetNamedItem("Type").Value == this.GetType().FullName)
            {
                ExcelReportOutput output = new ExcelReportOutput();
                output.OwnerWorkerInstanceID = new Guid(xNode.Attributes.GetNamedItem("WorkerID").Value);
                output.FinishTime = DateTime.Parse(xNode.Attributes.GetNamedItem("FinishTime").Value);

                output.ExcelReportFilePath = xNode.Attributes.GetNamedItem("ReportFilePath").Value;

                return output;
            }
            else
            {
                throw new Exception("Unable to instantiate output: invalid type specified in xml node");
            }
        }
    }
}
